<%@ page contentType="text/html;charset=UTF-8" %>
<script>
$(document).ready(function() {
	$('#propertyHouseinfoTable').bootstrapTable({

		  //请求方法
               method: 'post',
               //类型json
               dataType: "json",
               contentType: "application/x-www-form-urlencoded",
    	       //最低显示2行
    	       minimumCountColumns: 2,
               //是否显示行间隔色
               striped: false,
               //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
               cache: false,
               //是否显示分页（*）
               pagination: true,
                //排序方式
               sortOrder: "asc",
               //初始化加载第一页，默认第一页
               pageNumber:1,
               //每页的记录行数（*）
               pageSize: 10,
               //可供选择的每页的行数（*）
               pageList: [10, 25, 50, 100],
               //这个接口需要处理bootstrap table传递的固定参数,并返回特定格式的json数据
               url: "${ctx}/property/houseinfo/propertyHouseinfo/data",
               //默认值为 'limit',传给服务端的参数为：limit, offset, search, sort, order Else
               //queryParamsType:'',
               ////查询参数,每次调用是会带上这个参数，可自定义
               queryParams : function(params) {
               	var searchParam = $("#searchForm").serializeJSON();
               	searchParam.pageNo = params.limit === undefined? "1" :params.offset/params.limit+1;
               	searchParam.pageSize = params.limit === undefined? -1 : params.limit;
               	searchParam.orderBy = params.sort === undefined? "" : params.sort+ " "+  params.order;
                   return searchParam;
               },
               //分页方式：client客户端分页，server服务端分页（*）
               sidePagination: "server",
               contextMenuTrigger:"right",//pc端 按右键弹出菜单
               contextMenuTriggerMobile:"press",//手机端 弹出菜单，click：单击， press：长按。
               contextMenu: '#context-menu',
               onContextMenuItem: function(row, $el){
                   if($el.data("item") == "edit"){
                   		edit(row.id);
                   }else if($el.data("item") == "view"){
                       view(row.id);
                   } else if($el.data("item") == "delete"){
                        jp.confirm('确认要删除该房屋信息记录吗？', function(){
                       	jp.loading();
                       	jp.get("${ctx}/property/houseinfo/propertyHouseinfo/delete?id="+row.id, function(data){
                   	  		if(data.success){
                   	  			$('#propertyHouseinfoTable').bootstrapTable('refresh');
                   	  			jp.success(data.msg);
                   	  		}else{
                   	  			jp.error(data.msg);
                   	  		}
                   	  	})

                   	});

                   }
               },

               onClickRow: function(row, $el){
               },


               	onShowSearch: function () {
			$("#search-collapse").slideToggle();
		},
               columns: [{
                   field: 'buildingid.village.name',
                   title: '小区名称',
                   sortable: true,
                   sortName: 'b.villname'

               }, {
                   field: 'buildingid.buildingname',
                   title: '楼宇名称',
                   sortable: true,
                   sortName: 'b.buildingname'

               }
			,{
		        field: 'housetype',
		        title: '房屋类型',
		        sortable: true,
		        sortName: 'housetype',
                       formatter:function(value, row , index){
                           return jp.getDictLabel(${fns:toJson(fns:getDictList('house_type'))}, value, "-");
                       }

		    }
			,{
		        field: 'area',
		        title: '区域',
		        sortable: true,
		        sortName: 'area'

		    }
			,{
		        field: 'unit',
		        title: '单元号',
		        sortable: true,
		        sortName: 'unit'

		    }
			,{
		        field: 'houseowner.name',
		        title: '业主',
		        sortable: true,
		        sortName: 'houseowner.name'

		    }
			,{
		        field: 'updateDate',
		        title: '更新时间',
		        sortable: true,
		        sortName: 'updateDate'

		    }
			,{
		        field: 'remarks',
		        title: '备注信息',
		        sortable: true,
		        sortName: 'remarks'

		    }
			,{
		        field: 'floor',
		        title: '楼层号',
		        sortable: true,
		        sortName: 'floor'

		    }
			,{
		        field: 'room',
		        title: '房间号',
		        sortable: true,
		        sortName: 'room'

		    }
			,{
		        field: 'ifdecoration',
		        title: '是否装修',
		        sortable: true,
		        sortName: 'ifdecoration',
		        formatter:function(value, row , index){
		        	return jp.getDictLabel(${fns:toJson(fns:getDictList('yes_no'))}, value, "-");
		        }

		    }
			,{
		        field: 'ifvacancy',
		        title: '是否空置',
		        sortable: true,
		        sortName: 'ifvacancy',
		        formatter:function(value, row , index){
		        	return jp.getDictLabel(${fns:toJson(fns:getDictList('yes_no'))}, value, "-");
		        }

		    }
		     ]

		});


	  if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){//如果是移动端


		  $('#propertyHouseinfoTable').bootstrapTable("toggleView");
		}

	  $('#propertyHouseinfoTable').on('check.bs.table uncheck.bs.table load-success.bs.table ' +
                'check-all.bs.table uncheck-all.bs.table', function () {
          $('*').removeClass('selected');//移除class;
            $('#remove').prop('disabled', ! $('#propertyHouseinfoTable').bootstrapTable('getSelections').length);
            $('#view,#edit').prop('disabled', $('#propertyHouseinfoTable').bootstrapTable('getSelections').length!=1);

      });

		$("#btnImport").click(function(){
			jp.open({
			    type: 2,
                area: [500, 200],
                auto: true,
			    title:"导入数据",
			    content: "${ctx}/tag/importExcel" ,
			    btn: ['下载模板','确定', '关闭'],
				    btn1: function(index, layero){
					 jp.downloadFile('${ctx}/property/houseinfo/propertyHouseinfo/import/template');
				  },
			    btn2: function(index, layero){
				        var iframeWin = layero.find('iframe')[0]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
						iframeWin.contentWindow.importExcel('${ctx}/property/houseinfo/propertyHouseinfo/import', function (data) {
							if(data.success){
								jp.success(data.msg);
								refresh();
							}else{
								jp.error(data.msg);
							}
						   jp.close(index);
						});//调用保存事件
						return false;
				  },

				  btn3: function(index){
					  jp.close(index);
	    	       }
			});
		});


	 $("#export").click(function(){//导出Excel文件
	        var searchParam = $("#searchForm").serializeJSON();
	        searchParam.pageNo = 1;
	        searchParam.pageSize = -1;
            var sortName = $('#propertyHouseinfoTable').bootstrapTable("getOptions", "none").sortName;
            var sortOrder = $('#propertyHouseinfoTable').bootstrapTable("getOptions", "none").sortOrder;
            var values = "";
            for(var key in searchParam){
                values = values + key + "=" + searchParam[key] + "&";
            }
            if(sortName != undefined && sortOrder != undefined){
                values = values + "orderBy=" + sortName + " "+sortOrder;
            }

			jp.downloadFile('${ctx}/property/houseinfo/propertyHouseinfo/export?'+values);
	  })


	  $("#search").click("click", function() {// 绑定查询按扭
		  $('#propertyHouseinfoTable').bootstrapTable('refresh');
		});

	 $("#reset").click("click", function() {// 绑定查询按扭
		  $("#searchForm  input").val("");
		  $("#searchForm  select").val("");
		  $("#searchForm  .select-item").html("");
		  $('#propertyHouseinfoTable').bootstrapTable('refresh');
		});


	});

  function getIdSelections() {
        return $.map($("#propertyHouseinfoTable").bootstrapTable('getSelections'), function (row) {
            return row.id
        });
    }

  function deleteAll(){

		jp.confirm('确认要删除该房屋信息记录吗？', function(){
			jp.loading();
			jp.get("${ctx}/property/houseinfo/propertyHouseinfo/deleteAll?ids=" + getIdSelections(), function(data){
         	  		if(data.success){
         	  			$('#propertyHouseinfoTable').bootstrapTable('refresh');
         	  			jp.success(data.msg);
         	  		}else{
         	  			jp.error(data.msg);
         	  		}
         	  	})

		})
  }
  function refresh(){
  	$('#propertyHouseinfoTable').bootstrapTable('refresh');
  }
  function add(){
		 jp.go("${ctx}/property/houseinfo/propertyHouseinfo/form/add");
	}

  function edit(id){
	  if(id == undefined){
		  id = getIdSelections();
	  }
	  jp.go("${ctx}/property/houseinfo/propertyHouseinfo/form/edit?id=" + id);
  }

  function view(id) {
      if(id == undefined){
          id = getIdSelections();
      }
      jp.go("${ctx}/property/houseinfo/propertyHouseinfo/form/view?id=" + id);
  }
function getBuildinginfo(){
    jp.get("${ctx}/property/houseinfo/propertyHouseinfo/getBuildinginfo?id="+$('#buildingid\\.village\\.id option:selected') .val(), function(data){
        if(data.success){
            if(data.body.mapdata!=null){
                $('#buildingid').empty();
                $("#buildingid").append("<option value=''></option>");
                for(var i=0;i<data.body.mapdata.length;i++){
                    $("#buildingid").append("<option value='"+data.body.mapdata[i].value+"'>"+data.body.mapdata[i].label+"</option>");

                }
            }
        }else{
            jp.error(data.msg);
        }
    })
}
</script>